package com.ruipengkj.view.statementView;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

import com.ruipengkj.bean.TRole;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.commons.util.UUID;
import com.ruipengkj.component.JLabelJTextFieldComponent;
import com.ruipengkj.service.TRoleService;
import com.ruipengkj.view.base.BaseDialog;

public class MemberRole extends BaseDialog{
	private static final long serialVersionUID = 1L;
	private JButton okButton;//确定
	private JLabelJTextFieldComponent number = null;//会员编号
	private JLabelJTextFieldComponent des = null;///会员卡号
	private JLabelJTextFieldComponent nameTF = null; //姓名

	private TRoleService tCashCardService=BuildSpringApplication.getInstance().getTRoleServiceImpl();
	
	public MemberRole(JDialog jd, String title, boolean b) {
		
		super(jd,title,b);
		this.init();
		this.setSize(300, 550);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
	}
	private void init(){
		this.initViews();
		this.initListener();
	}
	private void initListener(){
		okButton.addActionListener(this);
		okButton.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		String name=nameTF.getText().getText().trim();//会员姓名
		String desc=des.getText().getText().trim();//会员姓名
		TRole tSendCardRecord=new TRole();
		tSendCardRecord.setRoleID(UUID.GenUUID15());
		tSendCardRecord.setDes(desc);
		tSendCardRecord.setName(name);
		if(e.getSource()==okButton){
			//确定
			try {
				tCashCardService.saveOrUpdateService(tSendCardRecord);
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			//BuildSpringApplication.getInstance().getTOpLogServiceImpl().modifyService("");
			this.dispose();
		}
	}
	private void initViews() {
		JPanel main_jp=new JPanel();
		BoxLayout boxLayout=new BoxLayout(main_jp,BoxLayout.Y_AXIS);
		main_jp.setLayout(boxLayout);
		
		number=new JLabelJTextFieldComponent("会员编号：",30);
		nameTF=new JLabelJTextFieldComponent("用 户 名：",30);
		des=new JLabelJTextFieldComponent(" 说 明：",30);
		number.getText().setEditable(false);
		JPanel jp1=new JPanel();
		okButton=new JButton("添加");
		jp1.add(okButton);
		
		main_jp.add(number);
		main_jp.add(nameTF);
		main_jp.add(des);
		main_jp.add(jp1);
		
		this.add(main_jp);
	}
	public void showDialog(){
		
		this.setVisible(true);
	}
}
